package vn.co.thn.android.videohot.common;

import com.android.volley.VolleyError;

import vn.co.thn.android.serviceconnect.callback.RequestError;
import vn.co.thn.android.serviceconnect.callback.RequestProcessCallBack;
import vn.co.thn.android.serviceconnect.request.RequestService;
import vn.co.thn.android.videohot.R;
import vn.co.thn.android.videohot.VHApp;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

public  class VHCommonFragment extends Fragment implements RequestProcessCallBack ,RequestError{
	protected FragmentManager mManager;
	private ProgressDialog progressDialog;
	protected RequestService mRequestService=new RequestService(VHApp.getInstance());
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		mManager = getActivity().getSupportFragmentManager();
		mRequestService.setRequestError(this);
		progressDialog = new ProgressDialog(getActivity());
		progressDialog.setIndeterminate(true);
		progressDialog.setCancelable(false);
		progressDialog.setMessage("loading...");
	}

	public Fragment findFragmentById(int resid) {
		return mManager.findFragmentById(resid);
	}

	@Override
	public void ShowProcess() {
		// TODO Auto-generated method stub
		progressDialog.show();
	}

	@Override
	public void HideProcess() {
		// TODO Auto-generated method stub
		progressDialog.dismiss();
	}

	public void setMessageProcess(String TextMessage) {
		progressDialog.setMessage(TextMessage);
	}

	//
	// replace Fragment
	protected void replaceFragment(Fragment fragment, int layoutId, FragmentManager fm) {
		final FragmentTransaction transaction = fm.beginTransaction();
		transaction.replace(layoutId, fragment);
		// transaction.addToBackStack(fragment.getClass().getName());
		transaction.commit();
	}

	// replace Fragment
	protected void replaceFragment(Fragment fragment) {
		final FragmentTransaction transaction = mManager.beginTransaction();
		transaction.replace(R.id.content, fragment);
		transaction.addToBackStack(fragment.getClass().getName());
		transaction.commit();
	}

	// replace Fragment whith layout id
	protected void replaceFragment(Fragment fragment, int layoutId) {
		final FragmentTransaction transaction = mManager.beginTransaction();
		transaction.replace(layoutId, fragment);
		transaction.addToBackStack(fragment.getClass().getName());
		transaction.commit();
	}

	// replace Fragment No back stack
	protected void replaceFragmentNoBackStack(Fragment fragment) {
		final FragmentTransaction transaction = mManager.beginTransaction();
		transaction.replace(R.id.content, fragment);
		transaction.commit();
	}

	// replace Fragment No back stack with layout ID
	protected void replaceFragmentNoBackStack(Fragment fragment, int layoutId) {
		final FragmentTransaction transaction = mManager.beginTransaction();
		transaction.replace(layoutId, fragment);
		transaction.commit();
	}

	// replace Fragment whith animation
	protected void replaceFragmentWithAnimation(Fragment fragment) {
		final FragmentTransaction transaction = mManager.beginTransaction();
		transaction.setCustomAnimations(R.anim.fragment_slide_right_enter, R.anim.fragment_slide_left_exit, R.anim.fragment_slide_left_enter,
				R.anim.fragment_slide_right_exit);
		transaction.replace(R.id.content, fragment);
		transaction.addToBackStack(fragment.getClass().getName());
		transaction.commit();
	}

	// replace Fragment whith animation and layout ID
	protected void replaceFragmentWithAnimation(Fragment fragment, int layoutId) {
		final FragmentTransaction transaction = mManager.beginTransaction();
		transaction.setCustomAnimations(R.anim.fragment_slide_right_enter, R.anim.fragment_slide_left_exit, R.anim.fragment_slide_left_enter,
				R.anim.fragment_slide_right_exit);
		transaction.replace(layoutId, fragment);
		transaction.addToBackStack(fragment.getClass().getName());
		transaction.commit();
	}

	// replace Fragment No back stack whith animation
	protected void replaceFragmentNoBackStackWithAnimation(Fragment fragment) {
		final FragmentTransaction transaction = mManager.beginTransaction();
		transaction.setCustomAnimations(R.anim.fragment_slide_right_enter, R.anim.fragment_slide_left_exit, R.anim.fragment_slide_left_enter,
				R.anim.fragment_slide_right_exit);
		transaction.replace(R.id.content, fragment);
		transaction.commit();
	}

	// replace Fragment No back stack whith Layout ID whith animation
	protected void replaceFragmentNoBackStackWithAnimation(Fragment fragment, int layoutId) {
		final FragmentTransaction transaction = mManager.beginTransaction();
		transaction.setCustomAnimations(R.anim.fragment_slide_right_enter, R.anim.fragment_slide_left_exit, R.anim.fragment_slide_left_enter,
				R.anim.fragment_slide_right_exit);
		transaction.replace(layoutId, fragment);
		transaction.commit();
	}

	public  void onDataRefresh(){
	}

	@Override
	public void onError(VolleyError error) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onException(Exception e) {
		// TODO Auto-generated method stub
		
	}
	
}
